package com.ahdms.es.util;

import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1UTCTime;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author qinxiang
 * @date 2021-03-18 15:55
 */
public abstract class DateUtils {

    /** 定义常量 **/
    public static final String DATE_JFP_STR = "yyyyMM";
    public static final String DATE_FULL_STR = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_SMALL_STR = "yyyy-MM-dd";
    public static final String DATE_KEY_STR = "yyMMddHHmmss";

    public static final DateFormat FULL_DATE_FORMAT = new SimpleDateFormat(DATE_FULL_STR);


    public static Date parse(String str){
        try {
            return FULL_DATE_FORMAT.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String format(Date date){
        return FULL_DATE_FORMAT.format(date);
    }

    public static String format(ASN1UTCTime date){
        try {
            return FULL_DATE_FORMAT.format(date.getDate());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static String format(ASN1GeneralizedTime date){
        try {
            return FULL_DATE_FORMAT.format(date.getDate());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

}
